package com.lowang.kafka.test;

import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {
        Properties configs = new Properties();
        configs.put("bootstrap.servers", "localhost:9092");
        configs.put("acks", "all");
        configs.put("retries ", 1);
        configs.put("buffer.memory", 33554432);
        configs.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        configs.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        Producer<String, String> producer = new KafkaProducer<>(configs);
        for (int i = 0; i < 100; i++) {
            ProducerRecord<String, String> pr = new ProducerRecord<String, String>("kafka-test", "key:" + String.valueOf(i), "value:" + String.valueOf(i));
            producer.send(pr);
        }
        producer.close();
    }
}
